<!DOCTYPE html>
<html>
<head>
    <title>属性管理</title>
    <#include "/common/import.ftl" >
    <script type="text/javascript">
        var modelId = '${modelId!""}';
        $(function () {
            $('#unitList').datagrid({
                title: '属性列表',
                iconCls: 'icon-ok',
                url: '${ctx}/audit/modeldetail/data.action?modelId=' + modelId,
                nowrap: false,
                striped: true,
                collapsible: false,
                fitColumns: true,
                singleSelect: true,
                rownumbers: true,
                remoteSort: false,
                idField: 'detailId',
                columns: [[
                    {field: 'columnEname', title: '属性英文名', width: 200},
                    {field: 'columnCname', title: '属性中文名称', width: 150}
                ]],
                toolbar: [
                    {
                        text: '增加',
                        iconCls: 'icon-add',
                        handler: function () {
                            saveUnit();
                        }

                    }, '-',
                    {
                        text: '删除',
                        iconCls: 'icon-cut',
                        handler: function () {
                            deleteunit();
                        }
                    }, '-',
                    {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function () {
                            editUnit();
                        }
                    },
                    '-',
                    {
                        text: '刷新',
                        iconCls: 'icon-reload',
                        handler: function () {
                            reload();
                        }
                    }
                ],
                onDblClickRow: function (row) {
                    editUnit();
                }
            });
        });

        // 增加模块
        function saveUnit() {
            $('#unitAddFrame').html('');
            var url = '${ctx}/audit/modeldetail/add.action?modelId=' + modelId;
            $('#unitAddFrame').attr("src", url);
            $('#unitAddWin').window('open');
        }

        // 修改模块
        function editUnit() {
            $('#unitAddFrame').html('');
            var node = getSelected();
            if (node) {
                var unitId = node.detailId;
                var url = '${ctx}/audit/modeldetail/add.action?id=' + unitId;
                $('#unitAddFrame').attr("src", url);
                $('#unitAddWin').window('open');
            }
        }

        // 删除模块
        function deleteunit() {
            var node = getSelected();
            if (node) {
                $.messager.confirm('确认', '您确定要删除:<font color=red>' + node.columnCname + ' </font>？', function (r) {
                    if (r) {
                        $.ajax({
                            type: "post",
                            url: "${ctx}/audit/modeldetail/del.action?id=" + node.detailId,
                            success: function (data, textStatus) {
                                var result = jQuery.parseJSON(data);
                                if (result.flag == 'T') {
                                    $.messager.alert('结果', '操作成功', 'info', function () {
                                        var rowIndex = $('#unitList').datagrid('getRowIndex', node);
                                        $('#unitList').datagrid('deleteRow', rowIndex);
                                    });
                                } else {
                                    $.messager.alert('提交结果', "操作失败：" + result.msg, 'error');
                                }
                            },
                            error: function () {
                                //请求出错处理
                            }
                        });
                    }
                });
            }
        }

        // 判断修改、删除前是否选中记录
        function getSelected() {
            var selected = $('#unitList').datagrid('getSelected');
            if (selected) {
                return selected;
            } else {
                $.messager.alert('提示', '请选择要操作的数据', 'info');
            }
        }

        // 刷新列表
        function reload() {
            var node = $('#unitList').datagrid('getSelected');
            if (node) {
                $('#unitList').datagrid('reload', node.unitId);
            } else {
                $('#unitList').datagrid('reload');
            }
        }

        // 关闭窗口
        function closeAdd() {
            $('#unitAddWin').window('close');
        }

        $('#unitAddWin').bind("close", reload);
    </script>
</head>

<body>

<table id="unitList"></table>

<!-- 查询窗口 -->
<div id="unitAddWin" class="easyui-window" title="信息" style="padding:5px;width: 550px;height:450;"
     iconCls="icon-search" closed="true" maximizable="false" minimizable="false"
     collapsible="false">
    <iframe scrolling="yes" frameborder="0" id="unitAddFrame" height="100%" width="100%"
            scrolling="No" frameborder="0"></iframe>
</div>

</body>
</html>